package com.yqRecite.util.result;

public class ResultUtil {

//    /**
//     * 使用枚举类设置返回结果
//     * @param resultCodeEnum
//     * @return
//     */
//    public static Result returnResult(ResultCodeEnum resultCodeEnum){
//        Result result = new Result();
//        result.setCode(resultCodeEnum.getCode());
//        result.setDesc(resultCodeEnum.getDesc());
//        result.setData(resultCodeEnum.getData());
//        return result;
//    }

    /**
     * 返回通用成功
     * @return Result
     * @param data
     */
    public static Result ok(Object data){
        Result result = new Result();
        result.setCode(ResultCodeEnum.SUCCESS);
        result.setData(data);
        return result;
    }
    /**
     * 返回通用成功
     * @return Result
     */
    public static Result ok(){
        Result result = new Result();
        result.setCode(ResultCodeEnum.SUCCESS);
        return result;
    }

    /**
     * 返回通用错误，未知错误
     * @return Result
     * @param data
     * @param desc
     */
    public static Result error(String desc, Object data){
        Result result = new Result();
        result.setCode(ResultCodeEnum.UNKNOWN_ERROR);
        result.setDesc(desc);
        result.setData(data);
        return result;
    }

    /**
     * 返回通用错误，未知错误
     * @return Result
     * @param desc
     */
    public static Result error(String desc){
        Result result = new Result();
        result.setCode(ResultCodeEnum.UNKNOWN_ERROR);
        result.setDesc(desc);
        return result;
    }

    /**
     * 返回通用失败，失败
     * @return Result
     * @param data
     * @param desc
     */
    public static Result fail(String desc, Object data){
        Result result = new Result();
        result.setCode(ResultCodeEnum.FAILURE);
        result.setDesc(desc);
        result.setData(data);
        return result;
    }

    /**
     * @param desc
     * @return
     */
    public static Result fail(String desc){
        Result result = new Result();
        result.setCode(ResultCodeEnum.FAILURE);
        result.setDesc(desc);
        return result;
    }
}
